﻿//--------------------------------------------------------------------------------------------------------------------------------------------------------
// <copyright file="Global.asax.cs">
//     Copyright © 2010 Oli Francis
//     This source code is subject to the terms and conditions of the MIT license. A copy of the license can be found in the license.txt 
//     file at the root of this distribution. By using this source code in any fashion, you are agreeing to be bound by the terms of the MIT License. 
//     You must not remove this notice from the software.
// </copyright>
// <author>Oli</author>
//-------------------------------------------------------------------------------------------------------------------------------------------------------

namespace TeamBrain.Web
{
    #region Using Statements

    using System.Web;
    using System.Web.Mvc;
    using System.Web.Routing;

    using Ninject;

    using TeamBrain.Web.Injection;

    #endregion

    /// <summary>
    /// Main Http application class
    /// </summary>
    public class MvcApplication : HttpApplication
    {
        /// <summary>
        /// Registers any global action filters global filters.
        /// </summary>
        public static void RegisterGlobalFilters(GlobalFilterCollection filters)
        {
            filters.Add(new HandleErrorAttribute());
        }

        /// <summary>
        /// Registers the routes used to evaluate inbound requests
        /// </summary>
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                "Default",
                "{controller}/{action}/{id}",
                new { controller = "Home", action = "Index", id = UrlParameter.Optional });
        }

        /// <summary>
        /// Event handler for when the web application starts
        /// </summary>
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            var kernel = new StandardKernel(new InjectionModule());
            DependencyResolver.SetResolver(new NinjectDependencyResolver(kernel));
            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);
        }
    }
}